import socket
from config import *

#对socket进行客户端的包装
class ClientSocket(socket.socket):
    def __init__(self):
        super(ClientSocket,self).__init__(socket.AF_INET,socket.SOCK_STREAM)
    def connect(self):
        super(ClientSocket,self).connect((SERVER_IP,SERVER_PORT))
    def recv_data(self):
        try:
            data = self.recv(1024).decode('utf-8')
        except Exception:
            return None
        return data
    def send_data(self,meassages):
        return self.send(meassages.encode('utf-8'))


def test():
    client_socket = ClientSocket()
    client_socket.connect()
    client_socket.send_data('你好，服务端')
    print(client_socket.recv_data())

if __name__ == '__main__':
    test()